#ifndef SORT_BUBBLE_HPP
#define SORT_BUBBLE_HPP

#include "../common.hpp"

YFWZ100_NS_BEGIN

template <typename T>
void bubble_sort(T arr[], int start, int end)
{
  for (int i = start; i < end - 1; i++) {
    for (int j = start + 1; j < end; j++) {
      if (arr[j - 1] > arr[j]) {
        T t = arr[j - 1];
        arr[j - 1] = arr[j];
        arr[j] = t;
      }
    }
  }
}

template <typename PointerLike>
void bubble_sort(PointerLike start, PointerLike end)
{
  for (PointerLike i = start; i != end - 1; i ++) {
    for (PointerLike j = start + 1; j != end; j ++) {
      if (*(j - 1) > *j) {
        swap(*(j - 1), *j);
      }
    }
  }
}

YFWZ100_NS_END

#endif//SORT_BUBBLE_HPP
